﻿/*******chanel.js***********/	
Pui.c={       
		navIndex:function(){//首页导航
		/*
			$("#Menu_common li a").each(function(i){
					$(this).mouseover(function(){
						$(this).addClass("current").parent().siblings().find(".current").removeClass("current");
						$("#MenuList").find("ul:visible").hide();
						$("#MenuList ul").eq(i).show();
					});
			});
			*/
			var bodyId=$("body").attr("id");
			var classId=bodyId.substring(2,bodyId.length);
			if ($("#Menu_common li#C-" + classId).html()) {
				$("#Menu_common li#C-" + classId + " a").addClass("current").parent().siblings().find(".current").removeClass("current");
				$("#Search select").val($("#" + classId).val());
				$("#MenuList").find("ul:visible").hide();
				$("#M-"+classId+"").show();
			}
			else {
				$("#Menu_common li a").eq(0).addClass("current").parent().siblings().find(".current").removeClass("current");
			}
			this.search();
				
		},
		search:function(){
				var bodyId=$("body").attr("id");
				var classId=bodyId.substring(2,bodyId.length);
				$("#Search select").val($("#"+classId).val());
				
				$("#Search input:button").click(function(){
					var values=$.trim($("#Search input[type='text']").val());
						if(!values) {
							alert("关键字不能为空");
							$("#Search input[type='text']").focus();
						}else{
							var keyword=encodeURIComponent(values.replace(/[\/_]/g,' '));
							var columnid=$("#Search select").val();
							if(columnid!=-1)
							var url="http://search.pomoho.com/videosearch.aspx?_keyword="+keyword+"&channelid="+channelid+"&columnid="+columnid;
							else var url="http://search.pomoho.com/videosearch.aspx?_keyword="+keyword+"&channelid="+channelid;
							window.open( url, '_blank' ); 
						}
				});
		},
		topic:function(result){
			//result=[{hits:124,answer:23,title:"奥运圣火西安传递开始 田亮首棒",athor:"我不是黄牛",timer:"2009-01-11 12:45:22",postId:582,topicId:7112,spaceurl:"onemax"},{hits:120,answer:23,title:"今年回家车票你买了吗2？",athor:"我不是黄牛",timer:"2009-01-11 12:45:22",postId:582,topicId:7112,spaceurl:"twomax"}]
			var arr = new Array();
			var arr1 = new Array();
			if(result.length==0||result==null||typeof(result[0].hits)=='undefined'){
				$("#Topics .list_v .s3").html("暂无帖子");
				return;
			}
			for (var i = 0; i < result.length; i++) {
				arr[0]= '<li>';
				arr[1]= '    <div class="s1">'+result[i].hits+'</div>';
				arr[2]= '	<div class="s2">'+result[i].answer+'</div>';
				arr[3]= '	<div class="s3"><a href="http://post.pomoho.com/topicview.aspx?postid='+result[i].postId+'&topicid='+result[i].topicId+'" title="'+result[i].title+'" target="_blank">'+result[i].title+'</a></div>';
				arr[4]= '	<div class="s4"><a href="http://home.pomoho.com/'+result[i].spaceurl+'.shtml" title="'+result[i].athor+'"  target="_blank">'+result[i].athor+'</a></div>';
				arr[5]= '	<div class="s5">'+result[i].timer+'</div></li>';
				arr1[i]=arr.join("");
			}
			$("#Topics .list_v").html(arr1.join(""));
		},
		hotTopic:function(result){
			for( var i=0;i<result.length;i++){
				$("#HotCol "+idArr[i]+"").html('<a target="_blank" title="'+result[i].title+'" href="http://post.pomoho.com/topicview.aspx?postid='+result[i].postId+'&topicid='+result[i].topicId+'">'+result[i].title+'</a>');
			}
			
		}
							
};	
/*********/


/***************************************频道首页轮换**************************************************/

$.fn.toggscroll=function(options){	
		var num=0;
		var o = {formbox:'#Fix a',tobox:'#Col_tuij .d',events:'click',area:'#Col_tuij',time:4000};
		var _autoscroll=true;
		if (options) $.extend(o, options);
		this.toggleShowDiv=function(){
			return $(o.formbox).each(function(i){
				if(o.events!="click")	
					$(this).bind(o.events,function(){$(this).click();});
			  	$(this).click(function(event){
					$(o.formbox+"[class=current]").removeClass("current");
			  		$(o.formbox).eq(i).addClass("current");
			  		if(o.events=="mouseover")
			  		{
			  			$(o.tobox).eq(i).show().siblings(":visible").not("dt").hide();
	
			  		}else{
			  			$(o.tobox).eq(i).fadeIn(300).siblings(":visible").not("dt").hide();
			  		}
					
			  		num=i;
			  		if($.browser.msie)
						$(this).blur().find("a").blur();
			  		return false
			  	});		
			})
		};

		var len = $(o.formbox).length;
		this.toggAuto = function(){
			if (!_autoscroll) 
				return;
			//var len = $(o.formbox).length;
			num = num < len - 1 ? num + 1 : 0;
			$(o.formbox).eq(num).click();
			
			
		};
		
		$(o.area).hover(function(){
			_autoscroll = false;
		}, function(){
			_autoscroll = true;
		});
		
		this.toggleShowDiv();
		if (o.auto != 0) {
		setInterval(this.toggAuto, o.time)
		}
		return false
	}

$.fn.autoscrolls=function(options,s,runtime,stime,direct){
	var o = {wrap:'',Box1:'',Box2:''};
		var _autoscroll=true;
		if (options) $.extend(o, options);
//		var s=41;//移动停顿距离
//		var runtime=10;//移动速度
//		var stime=240//停顿时间=(stime-s)*20/1000(秒)
	var stoptime=0;//计算器
	var stopstat=false;//是否停止
	$(o.Box2).html($(o.Box1).html());
	$(o.wrap)[0].scrollTop=0;
	$(o.wrap)[0].scrollLeft=0;
	this.sstart=function()//间断时间
	{	
		stoptime++;
		if(stoptime<=s&&direct){
			if($(o.wrap)[0].scrollTop-$(o.Box1)[0].offsetHeight>=0){
				$(o.wrap)[0].scrollTop=1;
			}else{
				$(o.wrap)[0].scrollTop+=1;
					//$(o.wrap).animate({scrollTop: -s*num},stime);
			}
			return
		}else if(stoptime<=s/2&&direct==0){
			if($(o.wrap)[0].scrollLeft-$(o.Box1)[0].offsetWidth>=0){
				$(o.wrap)[0].scrollLeft=2;//宽度翻倍问题
			}else{
				$(o.wrap)[0].scrollLeft+=2;
			}
			return
		}
		if(stopstat){return;}
		if(stoptime>stime) {
			stoptime=0;	
			return;
		}
	}

	this.tim=setInterval(this.sstart,runtime)
	$(o.wrap).hover(function(){
		stopstat=true
	},function(){
		stopstat=false
	});

}

